package com.zlz.server.controller;


import com.zlz.server.annotation.OperateLog;
import com.zlz.server.aspect.OperateLogAspect;
import com.zlz.server.enums.OprLevel;
import com.zlz.server.pojo.RespBean;
import com.zlz.server.pojo.Salary;
import com.zlz.server.service.ISalaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author efire
 * @since 2021-03-20
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {
    @Resource
    private ISalaryService iSalaryService;

    @ApiOperation(value = "获取所有的工资账套")
    @GetMapping("/")
    public RespBean getAllSalaries() {
        return RespBean.success(iSalaryService.list());
    }

    @ApiOperation(value = "添加工资账套")
    @PostMapping("/")
    @OperateLog(operationName = "添加工资账套", moduleName = "工资", level = OprLevel.LOW)
    public RespBean addSalary(@RequestBody Salary salary) {
        salary.setCreateDate(LocalDate.now());
        iSalaryService.save(salary);
        return RespBean.success();
    }

    @ApiOperation(value = "更新工资账套")
    @PutMapping("/")
    @OperateLog(operationName = "更新工资账套", moduleName = "工资", level = OprLevel.NORMAL)
    public RespBean updateSalary(@RequestBody Salary salary) {
        iSalaryService.updateById(salary);
        return RespBean.success();
    }

    @ApiOperation(value = "删除工资账套")
    @DeleteMapping("/{id}")
    @OperateLog(operationName = "删除工资账套", moduleName = "工资", level = OprLevel.HIGH)
    public RespBean delSalary(@PathVariable("id") Long id) {
        iSalaryService.removeById(id);
        return RespBean.success();
    }

    @ApiOperation(value = "批量删除工资账套")
    @DeleteMapping("/")
    @OperateLog(operationName = "批量删除工资账套", moduleName = "工资", level = OprLevel.HIGH)
    public RespBean batchDelSalary(Long[] ids) {
        OperateLogAspect.setOperateDetail(new ArrayList<>(Arrays.asList(ids)).toString());
        iSalaryService.removeByIds(Arrays.asList(ids));
        return RespBean.success();
    }
}
